package graduate.wangyaqi.Exam;

import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.transaction.Transactional;
import java.util.Optional;

@Service
public class ExamService {
    @Resource
    private ExamRepository examRepository;
    //保存数据
    @Transactional
    public void save(Exam exam){examRepository.save(exam);}
    //删除数据
    @Transactional
    public void delete(long id){examRepository.deleteById(id);}
    //查询数据
    @Transactional
    public Iterable<Exam> getAll(){
        Iterable<Exam> exams=examRepository.findAll();
        return exams;
    }
    @Transactional
    public Exam findExamByStuIDAndQuestionIDAndTaotiIDAndType(long stuId,long questionId,long taotiId,String type){
        return examRepository.findExamByStuIDAndQuestionIDAndTaotiIDAndType(stuId, questionId, taotiId, type);
    }
    @Transactional
    public Exam findExamById(long id){
        return examRepository.findExamById(id);
    }

    @Transactional
    public Iterable<Exam> findAllByStuIDAndTaotiIDOrderByIdDesc(Long stuId,Long taotaoId){
        return examRepository.findAllByStuIDAndTaotiIDOrderByIdDesc(stuId,taotaoId);
    }
    @Transactional
    public Exam findFirstByStuIDAndTaotiIDOrderByIdDesc(Long stuId, Long taotaoId){
        return examRepository.findFirstByStuIDAndTaotiIDOrderByIdDesc(stuId,taotaoId);
    }

    @Transactional
    public int countAllByStuIDAndTaotiID(Long stuId,Long taotaoId ){
        return examRepository.countAllByStuIDAndTaotiID(stuId,taotaoId);
    }

    @Transactional
    public int countByStuID(Long stuId ){
        return examRepository.countByStuID(stuId);
    }

    @Transactional
    public int countByStuIDNot(Long stuId ){
        return examRepository.countByStuIDNot(stuId);
    }
}
